<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
com.jxtti.model.User userInfo = com.jxtti.utils.AuthUtil.getUserInfo(request);
String orgId=null;
if(userInfo.getDistrictId()==null || userInfo.getDistrictId().equals("0")){ //非超管
	orgId=userInfo.getOrgId().toString();
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>投稿审核</title>
		<%@ include file="../../../common/Admin-list.jsp"%>
		<script type="text/javascript" src="<%=bpath %>Scripts/common/common.js"></script> 
 		<link rel="stylesheet" type="text/css" href="<%=basePath %>Themes/default/css/jquery.datetimepicker.css"/>    
		<script type="text/javascript" src="<%=basePath %>Scripts/jquery/jquery.datetimepicker.js"></script>
	
		<script type="text/javascript">
		$(function(){	
			
			var datagridUrl= '../ArticleList/list.json?type=isAudit&is_contribute=1&status=1';
			
			if(<%=orgId %>!=null){ //是否管理员
				$("#orgId").combotree("setValue",<%=orgId %>);	
				$("#orgId").combotree('disable');
				
			}
			
			if('${data.type}'=="audit"){ //我要投稿				
				datagridUrl= '../ArticleList/list.json?type=isAudit&is_contribute=1';
				
			}
			 
			
			//加载人员
			$('#dataGridArticleList').datagrid({
				height:'495',
				rownumbers:true,//设置为true将显示行数					
				striped:true, //设置为true将交替显示行背景
				fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
				animate:true,											
				idField:'id',//id字段	
				pagination : true,//分页控件
				pageSize : 10,
			    pageList : [10, 20, 30],
			    url : datagridUrl,//投稿审核
				loadMsg : '数据装载中......',
				singleSelect : true,//设置为 true，则只允许选中一行				
				columns:[[					          								
							{field:'id',hidden:true,editor:{type:'text'}},
							{field:'categoryID',title:'所属栏目',hidden:true,width:120,align:'center',editor:{type:'text'}},
							{field:'categoryName',title:'所属栏目',width:100,align:'left',editor:{type:'text'}},
							{field:'title',title:'文章标题',width:250,align:'left',editor:{type:'text'},								
								//预览
								formatter:function(value,row,index){									
									var html="";
									var url="/SiteIndex/article.htm?id="+encode64((row.id).toString())+'&preview=yes';								
									if($.trim(row.titleColor)!=""){
										html='<a href="<%=basePath %>'+url+'" target="_blank" style="color:'+row.titleColor+';"><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"></a> &nbsp;'+value;						   
									}else{
										html='<a href="<%=basePath %>'+url+'"  target="_blank" ><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"></a>&nbsp;'+value;						   
									}
						    		return html;						    	
						    	}
							},
							{field:'titleColor',title:'标题颜色',hidden:true,width:100,align:'center',editor:{type:'text'}},															
							{field:'issue',title:'显示',width:40,align:'center',editor:{type:'text'},
							    formatter:function(value){ 
						    		if(value=="1"){
						    			ss='<span disabled="disabled"><input type="checkbox" checked="checked" disabled="disabled"></span> ';
						    		}else{
						    			ss='<span disabled="disabled"><input type="checkbox" disabled="disabled"></span> ';
						    		}
						    		return ss;
						    	 }
							},	
							{field:'isHomePic',title:'图片推广',width:50,align:'center',editor:{type:'text'},
								formatter:function(value){ 
						    		if(value=="1"){
						    			return '√';
						    		}else{
						    			return '';
						    		}
						    	 }	
							}, 
							{field:'isRecommend',title:'置顶',width:50,align:'center',editor:{type:'text'},
								formatter:function(value){ 
						    		if(value=="1"){
						    			return '√';
						    		}else{
						    			return '';
						    		}						    		
						    	 }
							},
							{field:'status',title:'审核状态',width:50,align:'center',editor:{type:'text'},
								formatter:function(value){									
									if(value=="0"){
										return '草稿';
									}else if(value=="1"){
						    			return '<font color="#EE9A00">待审</font>';
						    		}else if(value=="2"){
						    			return '<font color="green">审核通过</font>';
						    		}else if(value=="3"){
						    			return '<font color="red">驳回</font>';
						    		}
						    	 }	
							},							
							{field:'sortID',title:'排序',hidden:true,width:40,align:'center',editor:{type:'text'}},	
							{field:'clicks',title:'点击数',width:40,align:'center',editor:{type:'text'}},	
							{field:'articleSite',title:'所属站点',width:50,align:'left',editor:{type:'text'},
								formatter:function(value){ 
						    		if(value=="0"){ // 0 外网,1内网，2内外网
						    			return '外网';
						    		}else if(value=="1"){
						    			return '内网';
						    		}else{
						    			return '外网&内网';
						    		}						    		
						    	 }
							},	
							{field:'modifyDate',title:'编辑时间',width:90,align:'center',editor:{type:'text'},
								formatter:function(value,row,index){  
	                        		var unixTimestamp = new Date(value);  
	                        		return unixTimestamp.format("yyyy-MM-dd hh:mm"); 
	                        	}
							},								
							{field:'fk_orgId',title:'组织机构id',hidden:true,width:100,align:'center',editor:{type:'text'}},	
							{field:'orgIdName',title:'投稿机构',width:100,align:'left',editor:{type:'text'}}
						]]    
	          
			});				
			
			
			
			// 所属类目			
			$('#categoryID').combotree({
				 url: '../ArticleCategory/getEasyUiTreeForSelect.json?isContribute=1',  //开放投稿
				 valueField: 'id',
	             textField: 'text',
	             editable: false ,//可编辑--定义用户是否可以直接输入
	             onLoadSuccess: function (node, data) {        
	              // $('#parentID').combotree('tree').tree("collapseAll"); 
	             }
			});	
			
			
		});
		
		function auditArticle(){ //审核文章 isAudit=yes
			var row = $('#dataGridArticleList').datagrid('getSelected');
			if (row) {				
				art.dialog.open('../ArticleList/updateInterfaceAudit.htm?type=edit&isAudit=yes&id='+row.id,{
					title: '',
					lock:true,
				  	width: '98%',
				    height: '98%'												   												   
				});
			}else{				
				$.messager.alert('系统提示', '请选择一行!', 'warning');
			}
		}
		
		function addArticle(){ //新增文章  
			art.dialog.open('../ArticleList/addInterfaceAudit.htm?type=add',{
				title: '',
				lock:true,
			  	width: '100%',
			    height: '100%'												   												   
			});
      	}
		
		function editArticle(){ //修改文章  
			var row = $('#dataGridArticleList').datagrid('getSelected');
			if (row) {				
				if(row.status=="0"||row.status=="3"){
					art.dialog.open('../ArticleList/updateInterfaceAudit.htm?type=edit&id='+row.id,{
						title: '',
						lock:true,
					  	width: '100%',
					    height: '100%'												   												   
					});
				}else{
					$.messager.alert('系统提示', '已经提交审核，暂不能修改！', 'warning');
				}
				
			}else{				
				$.messager.alert('系统提示', '请选择一行!', 'warning');
			}			
      	}
		
		function delArticle(){  //删除操作
			var row = $('#dataGridArticleList').datagrid('getSelected');
			if (row) {
				if(row.status=="0"||row.status=="3"){
					art.dialog({
						icon: 'question',	
						width:250,
					    content: '你确定删除该数据？',
					    ok: function () {
				    		$.ajax({
								type:'POST',
								dataType:'json',
								async:false,
								url:'../ArticleList/delete.json',
								data:{ids:row.id,delSub:true},
								success:function(data){
									if(data.success=true){									
										art.dialog.alert('删除成功！');
										window.location.reload();  									
									}else{
										art.dialog.alert('删除失败，请联系管理员！');
									}
								}
							});				    			
					    },
					    cancelVal: '取消',
					    cancel: true 
					});
				}else{
					$.messager.alert('系统提示', '稿件已经提交审核，不能删除！', 'warning');
				}
				
			}else{				
				$.messager.alert('系统提示', '请选择一行!', 'warning');
			}
      	} 
			
		</script>
		
	</head>
<body>		
		<div class="easyui-panel" fit="true" type="panel" border="false">			
		<table id="dataGridArticleList" type="dataGrid"	data-options="toolbar:'#toolBar'">
		</table>		
		<div id="toolBar" style="height: auto;padding:0px;">
			<!--表单  搜索栏-->
			<div id="filter" class="module">					
				<ul>				 
					<li>
						<input type="hidden" id="categoryIds" value="" />		
					</li>	
					<li>
						<label>投稿时间：</label>
						<input type="text" value="" id="timestart" class="inputdate" />						
					</li>
					<li>
						<label>-&nbsp;</label>
						<input type="text" value="" id="timeend" class="inputdate" />						
					</li>
					
					<li id="liOrgId">
						<label>投稿单位：</label>
						<select id="orgId" name="orgId" class="easyui-combotree" multiple style="width:250px;"   
        					data-options="url:'../district/findByPidAll.json?isCounty=yes',panelHeight:245"></select>						
					</li>					
					
					<li>
						<label>所属类目：</label>
						<select id="categoryID" name="categoryID" class="easyui-combotree" multiple style="width:150px;"></select>						
					</li>
				
					<li>
						<label>文章标题：</label>
						<input type="text" value="" id="title" style="width:250px;"/>						
					</li>
					<%if("audit".equals(request.getParameter("type"))){%>
					<li>					
						<label>&nbsp;&nbsp;&nbsp;&nbsp;稿件状态：</label>						
						<select id="articleAudit" class="datatype"  name="articleAudit">
							<option value="-1" selected="selected">所有投稿</option>						
							<option value="0">&nbsp;&nbsp;草稿</option>							
							<option  value="1">&nbsp;&nbsp;待审</option>	
							<option  value="2">&nbsp;&nbsp;审核通过</option>	
							<option  value="3">&nbsp;&nbsp;审核失败</option>	
						</select>		
					</li>	
					<%} %>	
					<li>
						<label>&nbsp;&nbsp;&nbsp;&nbsp;所属站点：</label>						
						<select id="articleSite" class="datatype"  name="articleSite">
							<option value="-1" selected="selected">所有文章</option>
							<option value="0">&nbsp;&nbsp;外网</option>							
							<option  value="1">&nbsp;&nbsp;内网</option>	
							<option  value="2">&nbsp;&nbsp;内网&外网&nbsp;&nbsp;&nbsp;&nbsp;</option>	
						</select>		
					</li>									
					<%if("audit".equals(request.getParameter("type"))){%>
					<li>
						&nbsp;&nbsp;&nbsp;&nbsp;
						 <input id="issue" type="checkbox" name="issue"  value="1"  style="width:10px;vertical-align:middle;" />
                	 	 <label for="issue" style="margin-right:8px;">网站显示</label>
	                	  
	                	 <input id="isHomePic" type="checkbox" name="isHomePic"  value="1" style="width:10px;vertical-align:middle;" />
	                	 <label for="isHomePic" style="margin-right:8px;">图片推广</label>
	                	  
	                	 <input id="is_contribute" type="checkbox" name="is_contribute" checked="checked" disabled="disabled" value="1" style="width:10px;vertical-align:middle;" />
	                	 <label for="is_contribute" style="margin-right:8px;">县级投稿</label>		                	 			
					</li>
					<%} %>	
					<li style="float:right;margin-right:200px;">
						<input type="button" class="btn btn-blue-h20-w2" value="查询" onclick="searchList()" />
					</li>
				</ul>
				<div class="clear"></div>
			</div>
			<!--表单  列表栏-->
			<div class="list module">
				<div class="hd">
					<h2 class="t">数据列表</h2>
					<span class="handle4filter" title="显示/隐藏查询条件"></span>
				</div>
				<div class="bd">
					<div id="toolbar">
						<ul id="buttonPlace">	
							<%if(null==request.getParameter("type")){%>						
							<li>
								<a href="javascript:auditArticle()" class="icon edit"  hideFocus="false"><span class = "glyphicon glyphicon-edit" style="display:in-line"></span>投稿审核</a>
							</li> 		
							<%} else{ %>
							
							<li>
								<a  href="javascript:addArticle()" class="icon add" hideFocus="false"><span class = "glyphicon glyphicon-plus" style="display:in-line"></span>增加</a>
							</li>
							<li>
								<a href="javascript:editArticle()" class="icon edit"  hideFocus="false"><span class = "glyphicon glyphicon-edit" style="display:in-line"></span>修改</a>
							</li> 				
							<li>
								<a href="javascript:delArticle()"  class="icon dele"  hideFocus="false"><span class = "glyphicon glyphicon-trash" style="display:in-line"></span>删除</a>
							</li>
							<%} %>
						</ul>
					</div>
				</div>
			</div>
		</div>		
		<div id="win"></div>
	</div>
	<script type="text/javascript">	
	$('#timestart').datetimepicker({		
		maxDate : 0 ,  //'new Date()'
		format:'Y-m-d',
		lang:'ch',
		timepicker:false
	});	
	
	$('#timeend').datetimepicker({		
		maxDate : 0 ,  //'new Date()'
		format:'Y-m-d',
		lang:'ch',
		timepicker:false,		
		onShow:function( ct ){				
				this.setOptions({		
					minDate:$('#timestart').val()?$('#timestart').val():false,formatDate:'Y-m-d'					
			    })			  
		}		
	});
		
	
	function searchList() {
		var queryParams = $('#dataGridArticleList').datagrid('options').queryParams;			
		queryParams.categoryID =$("#categoryID").combotree("getValues").join(',');//文章类目	
		queryParams.title = $('#title').val();
		queryParams.startTime = $('#timestart').val();
		queryParams.endTime = $('#timeend').val();
		queryParams.fk_orgId=$("#orgId").combotree("getValues").join(',');		
		
		if($('#articleSite').val()=="-1"){
			delete queryParams.articleSite;
		}else{
			queryParams.articleSite =$('#articleSite').val();
		}
		
		if($('#articleAudit').val()=="-1"){
			delete queryParams.status;
		}else{
			queryParams.status =$('#articleAudit').val();
		}
		
		
		if($('#issue').is(':checked')) {			
			queryParams.issue =$('#issue').val();//是否显示
		}else{
			delete queryParams.issue;
		}
		if($('#isHomePic').is(':checked')) {			
			queryParams.isHomePic=$('#isHomePic').val();//图片推广
		}else{
			delete queryParams.isHomePic; //从json中删除这一项			
		}		
		if($('#is_contribute').is(':checked')) {
			queryParams.is_contribute =$('#is_contribute').val();//县级投稿
		}else{			
			delete queryParams.is_contribute;
		}
		
		$('#dataGridArticleList').datagrid('load');
		$('#dataGridArticleList').datagrid('clearSelections');
	}
	
	$(function() {
		if($('#timestart').val()==""){					
			var d = new Date(); //获取今天日期
			d.setDate(d.getDate() - 30);				
			var mon=d.getMonth()+1;
			var day=d.getDate();			
			var str = d.getFullYear()+"-"+(mon<10 ? "0"+ mon : mon)+"-"+(day<10?"0"+day:day);			
			$('#timestart').val(str);			
		}
		
		if($('#timeend').val()==""){
			var d = new Date();
			var mon=d.getMonth()+1;
			var day=d.getDate();			
			var str = d.getFullYear()+"-"+(mon<10 ? "0"+ mon : mon)+"-"+(day<10?"0"+day:day);		
			$('#timeend').val(str);			
		}
	});
	
	</script>
</body>
</html>